import { createRouter, createWebHistory } from 'vue-router';
// import ShowCase from '../pages/showCasePages/index.vue';
// import AIMusicCompositon from '../pages/AIMusicCompositon.vue';
// import MyWorks from '../pages/MyWorks.vue';
// import AIModel from '../pages/AIModel.vue';
// import Shop from '../pages/Shop.vue';
// import ContactUs from '../pages/my/contactUs/index.vue';
// import MessageCenter from '../pages/my/messageCenter/index.vue';
// import useDuide from '../pages/my/useDuide/index.vue';
// import Help from '../pages/my/help/index.vue';
// import InfoSettings from '../pages/my/messageCenter/infoSettings.vue'
// import ChangePassword from '../pages/my/messageCenter/changePassword.vue'
// import BindPhone from '../pages/my/messageCenter/bindPhone.vue'

import { useUserStore } from '../store/user';
import { useRoute, useRouter } from 'vue-router'
import { isHidden } from 'element-plus/es/components/focus-trap/index.mjs';
const route = useRoute();


const routes = [
  { path: '/', redirect: '/home' }, 
  {
    path: '/:pathMatch(.*)*', // 通配符路由
    name: 'NotFound',
    component: () => import('../pages/NotFound.vue'),
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../pages/showCasePages/index.vue'),
  },
  {
    path: '/aimusic',
    name: 'AIMusic',
    component: () => import('../pages/AIMusicCompositon.vue'),
  },
  {
    path: '/myworks',
    name: 'MyWorks',
    component: () => import('../pages/MyWorks.vue'),
  },
  {
    path: '/aimodel',
    name: 'AIModel',
    component: () => import('../pages/AIModel.vue'),
  },
  {
    path: '/shop',
    name: 'Shop',
    component: () => import('../pages/Shop.vue'),
  },

  // ContactUs
  // MessageCenter
  // useDuide
  // Help

  {
    path: '/contactUs',  //联系我们
    name: 'contactUs',
    component: () => import('../pages/my/contactUs/index.vue'),
  },
  {
    path: '/messageCenter', // 消息中心
    name: 'messageCenter',
    component: () => import('../pages/my/messageCenter/index.vue'),
    redirect: '/messageCenter/infoSettings',
    children: [
      {
        path: 'infoSettings', // 信息设置子路由
        name: 'infoSettings',
        component: () => import('../pages/my/messageCenter/infoSettings.vue'),
      },
      {
        path: 'changePassword', // 修改密码子路由
        name: 'changePassword',
        component: () => import('../pages/my/messageCenter/changePassword.vue'),
      },
      {
        path: 'bindPhone', // 修改绑定手机子路由
        name: 'bindPhone',
        component: () => import('../pages/my/messageCenter/bindPhone.vue'),
      },
    ],
  },
  {
    path: '/useDuide',    // 使用指南
    name: 'useDuide',
    component: () => import('../pages/my/useDuide/index.vue'),
  },
  {
    path: '/help',     // 帮助与反馈
    name: 'help',
    component: () => import('../pages/my/help/index.vue'),
  },

  {
    path: '/wxCallback',     // 微信回调地址
    name: 'wxCallback',
    meta: { isHidden: true },
    component: () => import('../pages/wxCallback.vue'),
  },

];

const router = createRouter({
  history: createWebHistory(),
  routes,
});


router.beforeEach((to, from, next) => {

  const {userState} = useUserStore()
  if (userState.token) {
    next();
  } else {
    // userState.pageIndex = 0;
    // userState.isShowLogin = true
    userState.toPath = to.fullPath
    next();
  }
  // next();
});


export default router;
